package control;

import java.time.LocalDate;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.DatePicker;
import javafx.stage.Stage;
import javafx.scene.layout.*;

// 日期选择器
public class DatePickerDemo extends Application { 
	private Pane root = new Pane();
	private DatePicker dp;
	
	public static void main(String[] args) {
		Application.launch(args);
	}
	
	@Override
	public void start(Stage stage) {
		
		dp = new DatePicker(LocalDate.now());    // 设置初始显示日期为当前日期
//		DatePicker dp = new DatePicker(LocalDate.of(2018, 1, 1));
		dp.setEditable(false);
		root.getChildren().add(dp);
		
		Scene scene = new Scene(root, 300, 200);
		stage.setScene(scene);
		stage.setTitle("日期选择器");
		stage.show();
		
		// 属性监听
		dp.valueProperty().addListener(e -> {
			System.out.println(dp.getValue());	// 输出选择日期
			System.out.println("这是一年中的第" + dp.getValue().getDayOfYear() + "天");	// 一年中的第几天
		});
	}
}





